import { create } from 'zustand';
import { createJSONStorage, persist } from 'zustand/middleware';

export interface Course {
    id: number;
    title: string;
    desc?: string;  // 添加可选的描述字段
    image: string;
    teacher: string;
    level: string;
    price: string;
    originalPrice: string;
    students: number;
    duration: string;
    maxStudents: number;
    schedule: string;
    description: string;
    features: string[];
    tags: string[];
}

interface CourseState {
    courses: Course[];
}

interface CourseActions {
    getTopCourses: (limit: number) => Course[];
    getCourseById: (id: number) => Course | undefined;
}

// 模拟课程数据
const coursesData: Course[] = [
    {
        id: 1,
        title: '芭蕾舞基础入门课程',
        desc: '适合初学者的芭蕾基础课程',
        image: 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
        teacher: '李老师',
        level: '初级',
        price: '299',
        originalPrice: '399',
        students: 128,
        duration: '12课时',
        maxStudents: 20,
        schedule: '每周二、四 19:00-20:30',
        description: '本课程适合零基础学员，从基本姿态、把杆练习开始，循序渐进地掌握芭蕾舞基本技巧。',
        features: ['专业芭蕾舞教师授课', '小班教学，保证教学质量', '配备专业舞蹈教室', '定期举办汇报演出'],
        tags: ['热门', '新手推荐', '小班教学']
    },
    {
        id: 2,
        title: '现代舞进阶课程',
        desc: '现代舞技巧提升课程',
        image: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.png',
        teacher: '王老师',
        level: '中级',
        price: '399',
        originalPrice: '499',
        students: 89,
        duration: '16课时',
        maxStudents: 15,
        schedule: '每周一、三 20:00-21:30',
        description: '适合有基础的学员，提升现代舞技巧，培养艺术表现力。',
        features: ['专业现代舞教师', '进阶技巧教学', '舞蹈编排实践', '舞台表演机会'],
        tags: ['进阶', '提升技巧', '小班教学']
    },
    {
        id: 3,
        title: '民族舞进阶班',
        desc: '传统民族舞蹈技巧提升',
        image: 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
        teacher: '张老师',
        level: '中级',
        price: '359',
        originalPrice: '459',
        students: 95,
        duration: '14课时',
        maxStudents: 18,
        schedule: '每周二、五 18:30-20:00',
        description: '深入学习中国各民族特色舞蹈，提升舞蹈技巧和文化理解。',
        features: ['专业民族舞教师', '正宗舞蹈技法', '民族文化讲解', '舞台实践机会'],
        tags: ['热门', '民族特色', '小班教学']
    },
    {
        id: 4,
        title: '街舞基础班',
        desc: '流行街舞入门课程',
        image: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.png',
        teacher: '陈老师',
        level: '初级',
        price: '279',
        originalPrice: '379',
        students: 112,
        duration: '10课时',
        maxStudents: 20,
        schedule: '每周六、日 14:00-15:30',
        description: '零基础街舞入门，学习基本节奏感和舞步，培养音乐律动能力。',
        features: ['专业街舞教师', '基础动作教学', '音乐节奏训练', '小组展示机会'],
        tags: ['热门', '新手友好', '周末班']
    }
];

export const useCourseStore = create<CourseState & CourseActions>()(
    persist(
        (set, get) => ({
            courses: coursesData,
            getTopCourses: (limit: number) => {
                return [...get().courses]
                    .sort((a, b) => b.students - a.students)
                    .slice(0, limit);
            },
            getCourseById: (id: number) => {
                return get().courses.find(course => course.id === id);
            },
        }),
        {
            name: 'course-storage',
            storage: createJSONStorage(() => localStorage),
        }
    )
); 